//购物车混入
const mixinsCommon = {
    data:{
        cartData:[],//购物车数据
        visibleCart : false,//购物车可见性
    },
    computed:{
        cartGoodsCount(){
            return this.cartData.reduce((ret,prev)=>{
                return ret+= prev.data.length
            },0) || 0
        },
        cartGoodsPrice(){
            return this.cartData.reduce((ret,prev)=>{
                return ret+= prev.data.reduce((ret2,prev2)=>{
                    return ret2+= Number(prev2.guidePrice) //注意这里统计的是指导价
                },0)
            },0) || 0
        }
    },
    created() {
        this.getCartFromStorage()
    },
    methods:{

        //从储存中读取数据
        getCartFromStorage(){
            this.cartData = JSON.parse(localStorage.getItem("cart")) || []
        },

        //删除购物车中某个商品
        cartDelete(idxc,idxs){
            //询问框
            layer.confirm('要从购物车中删除这个型号吗', {
                btn: ['确定','取消'] //按钮
            }, ()=>{
                this.cartData[idxc].data.splice(idxs,1)
                let _temp = [...this.cartData] //复制
                localStorage.setItem("cart",JSON.stringify(_temp)) //放进本地储存
                layer.closeAll()
            }, function(){

            });

        },

        //清空购物车
        clearCart(){
            layer.confirm('确定清空吗？', {
                btn: ['确定','取消'] //按钮
            }, ()=>{
                this.cartData = []
                localStorage.removeItem('cart')
                layer.closeAll()
            }, function(){

            });

        },
        //打开购物车（触发相册插件）
        actToggleCart(act){
            if(act==1){
                this.visibleCart = true
                this.triggerLightBox ()//触发相册插件
            }else{
                this.visibleCart = false
            }
        },
        //触发相册组件
        triggerLightBox(){
            console.log('触发相册')
            this.$nextTick(() => {
                setTimeout(() => {
                    $("a[rel^='lightbox']").picbox({/* Put custom options here */}, null, function (el) {
                        return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
                    });
                }, 300)
            })
        }
    }
}